﻿
$(function(){
	
	change_cont('.difference_detail ul','.button_right','.button_left','470','.difference_detail li');
	//change_cont2('.switch1 ul','.switch1 .aright','.switch1 .aleft','798','.switch1 li');
	//change_cont2('.switch2 ul','.switch2 .aright','.switch2 .aleft','798','.switch2 li');
	//change_cont2('.switch3 ul','.switch3 .aright','.switch3 .aleft','798','.switch3 li');
        //change_cont2('.switch4 ul','.switch4 .aright','.switch4 .aleft','798','.switch4 li');
	//change_cont2('.switch5 ul','.switch5 .aright','.switch5 .aleft','798','.switch5 li');
	//change_cont2('.switch6 ul','.switch6 .aright','.switch6 .aleft','798','.switch6 li');
	//change_cont2('.switch7 ul','.switch7 .aright','.switch7 .aleft','798','.switch7 li');
})


    //单体切换换样式
    function change_cont(chang_obj,right_obj,left_obj,Swidth,num_obj){
  
      var index = 0 , num = $(num_obj).length;
       if(num >1){//addclass_right
         $(right_obj).addClass('yes_to_go_right');
       }
       function NextPage(){//下一页
           if(index>num-1){
            index = num-1 ;//0//如果要交换切换则为0
         }else if(index==num-1) {
            $(left_obj).addClass('yes_to_go_left');
            $(right_obj).removeClass('yes_to_go_right');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }else {
            $(left_obj).addClass('yes_to_go_left');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }
      }
        function PrevPage() { //上一页
        if(index<0) {
          index = 0 ;//num-1//如果要交换切换则为num-1
         }else if(index==0) {
            $(right_obj).addClass('yes_to_go_right');
            $(left_obj).removeClass('yes_to_go_left');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }else {
            $(right_obj).addClass('yes_to_go_right');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }
      
       }
       $(right_obj).click(function(){
       index++ ;
       NextPage();
       });
        $(left_obj).click(function(){
       index-- ;
       PrevPage();
       });
    }  
	
	//单体切换换样式2
    function change_cont2(chang_obj,right_obj,left_obj,Swidth,num_obj){
  
      var len = $(num_obj).length;
	  var index = 0 ,i=3, num = Math.ceil(len / i);
	    if(num ==1 || num <1){//隐藏
         $(right_obj).hide();
		 $(left_obj).hide();

       }
       if(num >1){//addclass_right
         $(right_obj).addClass('agrayright');
       }
       function NextPage(){//下一页
           if(index>num-1){
            index = num-1 ;//0//如果要交换切换则为0
         }else if(index==num-1) {
            $(left_obj).addClass('agrayleft');
            $(right_obj).removeClass('agrayright');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }else {
            $(left_obj).addClass('agrayleft');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }
      }
        function PrevPage() { //上一页
        if(index<0) {
          index = 0 ;//num-1//如果要交换切换则为num-1
         }else if(index==0) {
            $(right_obj).addClass('agrayright');
            $(left_obj).removeClass('agrayleft');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }else {
            $(right_obj).addClass('agrayright');
            $(chang_obj).stop(true, false).animate({left: -index*Swidth+"px"},600);
         }
      
       }
       $(right_obj).click(function(){
       index++ ;
       NextPage();
       });
        $(left_obj).click(function(){
       index-- ;
       PrevPage();
       });
    }  